package mysql

import "gorm.io/gorm"

type Department struct {
	gorm.Model
	DepartmentName string `gorm:"type:varchar(30)" json:"departmentName"` //科室名称
	Pid            int64  `gorm:"int(11);default:0" json:"pid"`           //父级id
}

func (d *Department) FindDepartment() (dep []*Department, err error) {
	err = DB.Model(&d).Find(&dep).Error
	if err != nil {
		return nil, err
	}
	return dep, nil
}
func (d *Department) FindDepartments(keyword string) (dep *Department, err error) {
	err = DB.Model(&d).Where("department_name=?", keyword).Find(&dep).Error
	if err != nil {
		return nil, err
	}
	return dep, nil
}

func (d *Department) SearchDepartment(id int64) (dep []*Department, err error) {
	err = DB.Model(&d).Where("id=? OR pid=?", id, id).Find(&dep).Error
	if err != nil {
		return nil, err
	}
	return dep, nil
}
